package com.knight.mall.admin.web.utils;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.util.AntPathMatcher;
import org.springframework.util.PathMatcher;

public class PathUtils {

	private static PathMatcher pathMatcher = new AntPathMatcher();

	public static boolean matches(String lookupPath, List<String> excludeUrls) {
		if (excludeUrls != null) {
			for (String pattern : excludeUrls) {
				if (pathMatcher.match(pattern, lookupPath)) {
					return true;
				}
			}
			return false;
		} else {
			return true;
		}
	}

	/**
	 * 判断ajax请求
	 * 是 返回true
	 * @param request
	 * @return
	 */
	public static boolean isAjax(HttpServletRequest request) {
		return (request.getHeader("X-Requested-With") != null
				&& "XMLHttpRequest".equals(request.getHeader("X-Requested-With").toString()));
	}

}
